﻿/* Copyright (C) 2006,2007 ScriptDevCN <http://silverwings.googlecode.com/>
 * 该脚本由银翼团队 黑暗精灵 翻译
*/

/* ScriptData
SDName: Boss_Highlord_Mograine
SD%Complete: 100
SDComment: 
EndScriptData */

#include "../../sc_defines.h"

//All horsemen
#define SPELL_SHIELDWALL           29061
#define SPELL_BESERK               26662

// highlord mograine
#define SPELL_MARK_OF_MOGRAINE     28834
#define SPELL_RIGHTEOUS_FIRE       28882 // Applied as a 25% chance on melee hit to proc. m_creature->GetVictim()

#define SAY_TAUNT1                 "  别多说废话啦，让他们来吧，我们会把他们的骨头，碾成灰的。  "
#define SAY_TAUNT2                 "  保留你的愤懑，压抑你的怒火吧！很快，你们就只能体会到挫折感了。 "
#define SAY_TAUNT3                 "  生命本身毫无意义，只有死亡，才能让你了解人性的真谛……  "
#define SAY_AGGRO1                 "  你寻死吗？  "
#define SAY_AGGRO2                 "  休想过去！  "
#define SAY_AGGRO3                 "  不许动！"
#define SAY_SLAY1                  "  你死后，也永远不得安宁……  "
#define SAY_SLAY2                  "  这是主人的意志……  "
#define SAY_SPECIAL                "  臣服于大领主的力量吧！  "
#define SAY_DEATH                  "  我……自由啦……希望还不是太迟，圣光啊！请再多给我一些……时间……  "

#define SOUND_TAUNT1               8842
#define SOUND_TAUNT2               8843
#define SOUND_TAUNT3               8844
#define SOUND_AGGRO1               8835
#define SOUND_AGGRO2               8836
#define SOUND_AGGRO3               8837
#define SOUND_SLAY1                8839
#define SOUND_SLAY2                8840
#define SOUND_SPECIAL              8841
#define SOUND_DEATH                8838

#define SPIRIT_OF_MOGRAINE         16775

struct MANGOS_DLL_DECL boss_highlord_mograineAI : public ScriptedAI
{
    boss_highlord_mograineAI(Creature *c) : ScriptedAI(c) {EnterEvadeMode();}

    uint32 Mark_Timer;
    uint32 RighteousFire_Timer;
    bool ShieldWall1;
    bool ShieldWall2;
    bool InCombat;

    void EnterEvadeMode()
    {       
        Mark_Timer = 20000; // First Horsemen Mark is applied at 20 sec.
        RighteousFire_Timer = 2000; // applied approx 1 out of 4 attacks
        ShieldWall1 = true;
        ShieldWall2 = true;
        InCombat = false;

        m_creature->RemoveAllAuras();
        m_creature->DeleteThreatList();
        m_creature->CombatStop();
        DoGoHome();
    }

    void InitialYell()
    {
        if(!InCombat)
        {
            switch(rand()%3)
            {
            case 0:
                DoYell(SAY_AGGRO1,LANG_UNIVERSAL,NULL);
                DoPlaySoundToSet(m_creature,SOUND_AGGRO1);
                break;

            case 1:
                DoYell(SAY_AGGRO2,LANG_UNIVERSAL,NULL);
                DoPlaySoundToSet(m_creature,SOUND_AGGRO2);
                break;

            case 2:
                DoYell(SAY_AGGRO3,LANG_UNIVERSAL,NULL);
                DoPlaySoundToSet(m_creature,SOUND_AGGRO3);
                break;
            }
        }
    }

    void KilledUnit()
    {
        switch(rand()%2)
        {
        case 0:
            DoYell(SAY_SLAY1,LANG_UNIVERSAL,NULL);
            DoPlaySoundToSet(m_creature,SOUND_SLAY1);
            break;

        case 1:
            DoYell(SAY_SLAY2,LANG_UNIVERSAL,NULL);
            DoPlaySoundToSet(m_creature,SOUND_SLAY2);
            break;
        }
    }

    void JustDied(Unit* Killer)
    {
        DoYell(SAY_DEATH,LANG_UNIVERSAL,NULL);
        DoPlaySoundToSet(m_creature, SOUND_DEATH);
    }

    void AttackStart(Unit *who)
    {
        if (!who)
            return;

        if (who->isTargetableForAttack() && who!= m_creature)
        {
            //Begin melee attack if we are within range
            DoStartMeleeAttack(who);
            InitialYell();
            InCombat = true;
        }
    }

    void MoveInLineOfSight(Unit *who)
    {
        if (!who || m_creature->getVictim())
            return;

        if (who->isTargetableForAttack() && who->isInAccessablePlaceFor(m_creature) && m_creature->IsHostileTo(who))
        {
            float attackRadius = m_creature->GetAttackDistance(who);
            if (m_creature->IsWithinDistInMap(who, attackRadius) && m_creature->GetDistanceZ(who) <= CREATURE_Z_ATTACK_RANGE && m_creature->IsWithinLOSInMap(who))
            {
                if(who->HasStealthAura())
                    who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);

                DoStartMeleeAttack(who);
                InitialYell();
                InCombat = true;
            }
        }
    }

    void UpdateAI(const uint32 diff)
    {
        //Return since we have no target
        if (!m_creature->SelectHostilTarget() || !m_creature->getVictim())
            return;

        // Mark of Mograine
        if(Mark_Timer < diff)
        {
            DoCast(m_creature->getVictim(),SPELL_MARK_OF_MOGRAINE);
            Mark_Timer = 12000;
        }else Mark_Timer -= diff;

        // Shield Wall - All 4 horsemen will shield wall at 50% hp and 20% hp for 20 seconds 
        if(ShieldWall1 && (m_creature->GetHealth()*100 / m_creature->GetMaxHealth()) < 50)
        {
            if(ShieldWall1)
            {
                DoCast(m_creature,SPELL_SHIELDWALL);
                ShieldWall1 = false;
            }
        }
        if(ShieldWall2 && (m_creature->GetHealth()*100 / m_creature->GetMaxHealth()) < 20)
        {
            if(ShieldWall2)
            {
                DoCast(m_creature,SPELL_SHIELDWALL);
                ShieldWall2 = false;
            }
        }

        // Righteous Fire
        if(RighteousFire_Timer < diff)
        {
            if(rand()%4 == 1) // 1/4
            {
                DoCast(m_creature->getVictim(),SPELL_RIGHTEOUS_FIRE);
            }
            RighteousFire_Timer = 2000; // right
        }else RighteousFire_Timer -= diff;

        DoMeleeAttackIfReady();
    }
}; 
CreatureAI* GetAI_boss_highlord_mograine(Creature *_Creature)
{
    return new boss_highlord_mograineAI (_Creature);
}


void AddSC_boss_highlord_mograine()
{
    Script *newscript;
    newscript = new Script;
    newscript->Name="boss_highlord_mograine";
    newscript->GetAI = GetAI_boss_highlord_mograine;
    m_scripts[nrscripts++] = newscript;
}
